#include<iostream>
#include<unordered_set>
#define mod 998244353
constexpr int mxn=1003;
int n;
std::unordered_set<std::string>st,f[mxn][mxn];
void oper(std::unordered_set<std::string>&st,std::string s){
  if(st.count(s))return;
  st.emplace(s);
  int a=s.find("AA"),b=s.find("BB"),c=s.find("BA");
  if(a==-1&&b==-1&&c==-1)return;
  std::string t;
  while(a!=-1){
    t=s,t.erase(a,2),oper(st,t);
    a=s.find("AA",a+1);
  }
  while(b!=-1){
    t=s,t.erase(b,2),oper(st,t);
    b=s.find("BB",b+1);
  }
  while(c!=-1){
    t=s,t.erase(c,2),oper(st,t);
    c=s.find("BA",c+1);
  }
  return;
}
int main(){
  // freopen("song.in","r",stdin);
  // freopen("song.out","w",stdout);
  std::string s;
  std::cin>>s;
  n=s.size();
  if(n<=100){
    for(int i=0;i<n-1;++i){
      if(s[i]=='A'&&s[i+1]=='A'||s[i]=='B')
        f[i+1][i+2].emplace("");
    }
    for(int l=1;l<=n;++l){
      for(int i=1;i<=n-l+1;++i){
        int j=i+l-1;
        f[i][j].emplace(s.substr(i-1,l));
        for(int k=i;k<j;++k){
          for(std::string x:f[i][k]){
            for(std::string y:f[k+1][j]){
              std::string t=x+y;
              if(f[i][j].count(t))continue;
              f[i][j].emplace(t);
              std::string a=x,b=y;
              while(a.size()&&b.size()&&
                    (a.back()=='B'||a.back()=='A'&&b.front()=='A')){
                a.pop_back(),b.erase(0,1);
                t=a+b;
                if(f[i][j].count(t))continue;
                f[i][j].emplace(t);
              }
            }
          }
        }
      }
    }
    std::cout<<f[1][n].size()<<std::endl;
  }else{
    oper(st,s);
    std::cout<<st.size()<<std::endl;
  }
  return 0;
}